<html>
<head>
<script type="text/javascript">
function onLoad() {
  window.domAutomationController.reset = function() {
    window.domAutomationController._loaded = false;
    window.domAutomationController._succeeded = false;
    window.domAutomationController._finished = false;
    window.requestAnimationFrame(draw);
  };
  window.domAutomationController.send("LOADED");
}

function draw() {
  // Render some WebGL into a fresh canvas to ensure the GPU process
  // was created.
  var canvas = document.createElement("canvas");
  canvas.width = 32;
  canvas.height = 32;
  gl = canvas.getContext("webgl");
  if (!gl) {
    console.log("Failed to fetch WebGL context");
    window.domAutomationController.send("FAILED");
    return;
  }

  gl.clearColor(1, 0, 0, 1);
  gl.clear(gl.COLOR_BUFFER_BIT);
  var pixels = new Uint8Array(4);
  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
  var tolerance = 1;
  if (Math.abs(pixels[0] - 255) > tolerance ||
      Math.abs(pixels[1] - 0) > tolerance ||
      Math.abs(pixels[2] - 0) > tolerance ||
      Math.abs(pixels[3] - 255) > tolerance) {
    console.log("Expected (255, 0, 0, 255), got (" +
      pixels[0] + ", " +
      pixels[1] + ", " +
      pixels[2] + ", " +
      pixels[3] + ")");
    window.domAutomationController.send("FAILED");
    return;
  }

  window.domAutomationController.send("SUCCESS");
}
</script>
</head>
<body onload="onLoad()">
GPU process crash test running.
</body>
</html>
